package com.zny.sescore.rule.constant;


import com.zny.sescore.model.CodeName;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @version: V1.0
 * @author: zhangnayi
 * @className: RelationOptEnum
 * @packageName: com.palmdoctor.mb.base.rule.constant
 * @description: 逻辑运算法符枚举
 * @data: 2021-08-08 21:31
 **/
@RuleConstant(value = "logical_opt", name = "逻辑运算符")
public enum LogicalOptEnum implements IRuleConstant {

    OR("||", "或者"),
    AND("&&", "并且"),
    ;

    private String code;

    private String name;

    LogicalOptEnum(String code, String name) {
        this.code = code;
        this.name = name;
    }

    @Override
    public List<CodeName> codeNames() {
        return Stream.of(values())
                .map(v -> new CodeName(v.code, v.name))
                .collect(Collectors.toList());
    }

    public static LogicalOptEnum getByCode(String code) {
        if (code == null) {
            return null;
        }
        for (LogicalOptEnum optEnum : values()) {
            if (Objects.equals(optEnum.code, code)) {
                return optEnum;
            }
        }
        return null;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getName() {
        return name;
    }
}
